using System.Text;
using System.Web;

namespace Toast.Utils
{
    public class EncodingUtils
    {
        public static string UrlSafeEncode(string input)
        {
            return Core.ToastCore.SeperateFiles
                       ? HttpUtility.UrlEncode(input)
                       : HttpServerUtility.UrlTokenEncode(Encoding.Default.GetBytes(input));
        }

        public static string UrlSafeDecode(string input)
        {
            return Core.ToastCore.SeperateFiles
                       ? input.Contains(" ") ? input : HttpUtility.UrlDecode(input) // TODO: Fix this, checking for whitespace to decide whether string is URL encoded isnt great.
                       : Encoding.Default.GetString(HttpServerUtility.UrlTokenDecode(input));
        }
    }
}